package com.lagou.wwyan.rpc;

import com.lagou.wwyan.rpc.client.RpcConsumer;
import com.lagou.wwyan.rpc.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.stereotype.Component;

@SpringBootApplication
@Component
public class RpcClientApplication implements ApplicationRunner {
	@Autowired
	private RpcConsumer consumer;

	public static void main(String[] args) throws InterruptedException {
		SpringApplication.run(RpcClientApplication.class, args);
	}

	/**
	 * 启动完之后执行
	 * @param args
	 * @throws Exception
	 */
	@Override
	public void run(ApplicationArguments args) throws Exception {
		new Thread(() -> {
			UserService service= consumer.createProxy(UserService.class);
			//2.循环给服务器写数据
			while (true){
				System.out.println("---开始-----");
				try {
					String result = service.sayHello("are you ok !!");
					System.out.println("sayHello:"+result);
					System.out.println("---结束-----");
					System.out.println("");
					Thread.sleep(2000);
				} catch (Exception e) {
					e.printStackTrace();
				}

			}
		}).start();
	}
}
